/*
 *
 * Copyright (C) 1997 Jayakrishnan Nair jk@csr.uvic.ca
 * WWW: http://www.csc.uvic.ca/~jk
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */
import java.awt.*;
import java.util.*;

class SilverScreen extends Canvas {
  int width;
  int height;
  SlideProjector slideProjector;
  

    public SilverScreen(int width, int height,SlideProjector s) {
        this.width = width;
        this.height = height;
	slideProjector = s;
       //resize(width,height);
    }

public Dimension preferredSize() {
    return new Dimension(width,height);
}

public void paint(Graphics g) {

    Dimension d = size();
    g.setColor(Color.blue);
    g.fillRect(0,0,width,height);

}

public void displayImage(Image img) {
    Graphics g = getGraphics();
    Random r = new Random();
    int val = r.nextInt();
    
    
    int w = slideProjector.getProjectorWidth();
    int h = slideProjector.getProjectorHeight();
    int j;
    
    int delay = slideProjector.getDelay();

    val %= 7;

    switch (val) {

    case 0:
      j = w;
      for(int i = w; i >=0; i--) {
	g.drawImage(img,j,i,this);
	j--;
	for (int k = 0; k < delay; k++);
      }
      break;
    case 1:
      for(int i = w; i >= 0; i--) {
	g.drawImage(img,i,0,this);
	for (int k = 0; k < delay; k++);
      }
      break;
    case 2:
      for(int i = w; i >= 0; i--) {
	g.drawImage(img,0,i,this);
	for (int k = 0; k < delay; k++);
      }
      break;
    case 3:
      for(int i = 0; i < w; i++) {
	g.drawImage(img,0,i-w,this);
	for (int k = 0; k < delay; k++);
      }
      break;
    case 4:
      j = 0;
      for(int i = 0; i < w; i++) {
	g.drawImage(img,i-w,0,this);
	j++;
	for (int k = 0; k < delay; k++);
      }
      break;
    case 5:
      j = 0;
      for(int i = 0; i < h; i++) {
	g.drawImage(img,j-h,i-h,this);
	j++;
	for(int k = 0; k < delay; k++);
      }
      break;
    default:
      for(int i = w; i >= 0; i--) {
	g.drawImage(img,0,i,this);
	for (int k = 0; k < delay; k++);
      }
      break;
    }

    this.getToolkit().sync();
}


public void clearDisplay() {
    Graphics g = getGraphics();
    Dimension d = size();
    g.setColor(Color.black);
    g.fillRect(0,0,width,height);
}



}
